package org.leviatan.dataharbour.db.impl;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.log4j.Logger;
import org.leviatan.dataharbour.db.Database;

public class MySQLController implements Database {


	// connection URL structure jdbc:subprotocol:subname
	// jdbc:mysql://host_name:port/dbname
	private String host = null;
	private String dbname = null;
	private int port = 3306;
	private Connection con = null;
	
	static Logger logger = Logger.getLogger(MySQLController.class);
	
	
	
	public MySQLController() { }
	
	public MySQLController(String aHost, String aDBname, int aPort) {
		this();
		this.host 	= aHost;
		this.dbname = aDBname;
		this.port 	= aPort;
	}
	
	
	public void closeConnection() {
		// TODO Auto-generated method stub
	}

	public Connection openConnection() throws Exception {
		if ( (host == null) || (dbname == null) ) {
			logger.error("Host or db name is null, or both!");
			throw new Exception("Host or database name is null");
		}
		try {
			con = java.sql.DriverManager.getConnection("jdbc:mysql://"+ host +":"+ port + "/" + dbname);
		} catch (SQLException e) {
			logger.error("Couldn't get jdbc connection!");
			e.printStackTrace();
		}
		return con;
	}

	public Object retrieveData() {
		
		return null;
	}

	public void storeData() {

	}
	
	public void createDefaultTable() {
		
	}
	
}
